package com.tjsinfo.tjsoa.fileDocument.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.fileDocument.bo.IFileDocumentUserBo;

public class DownUserAction extends Action{
	private IFileDocumentUserBo documentUserBo;
	public void setDocumentUserBo(IFileDocumentUserBo documentUserBo) {
		this.documentUserBo = documentUserBo;
	}
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		String groupids = request.getParameter("groupids");
		String groupid = groupids;
		String users = request.getParameter("users");
		String str = "shi";
		if (groupids!=null && !"".equals(groupids)) {
			groupids = "'"+groupids.replace(",", "','");
			groupids = groupids.substring(0, groupids.length()-2);
			documentUserBo.deleteByGroup(groupids);
		}
		
		if (groupid!=null && !"".equals(groupid)) {
			List<String>grouplist = new ArrayList();
			String[] group = groupid.split(",");
			for (int i = 0; i < group.length; i++) {
				if (group[i]!=null && !"".equals(group[i])) {
					grouplist.add(group[i]);
				}
			}
			List<Integer> userlist = new ArrayList();
			String[] user = users.split(",");
			for (int i = 0; i < user.length; i++) {
				if (user[i]!=null && !"".equals(user[i])) {
					userlist.add(Integer.valueOf(user[i]));
				}
			}
			documentUserBo.groupUser(grouplist, userlist);
			str = "fou";
		}
		return new ActionForward("/intoDownUser.do?first="+str+"");
	}
}
